package com.epam.tasks;

import java.util.List;

import com.epam.text_elements.Sentence;
import com.epam.text_elements.Text;
import com.epam.text_elements.Word;

public class FirstSentenceWordOccurence {

	// NOT A BOOLEAN METHOD BECAUSE WE NEED TO POINT OUT THE
	// CONCRETE WORDS FROM THE SENTENCE
	public static String findOccurence(Text text, Sentence firstSentence) {
		List<Word> listOfWords = text.getAllWords();
		String res = "TASK NUMBER 3\n";
		int numOfWords = firstSentence.getNumOfWords();
		for (int i = 0; i < numOfWords; i++) {
			// if a word from the 1st sentence occurs later in the list of all
			// words but is not itself (lastIndexOf and !=i)
			if (listOfWords.lastIndexOf(listOfWords.get(i)) == i) {
				res += "The word \"" + listOfWords.get(i)
						+ "\" does not occur in the later sentences!\n";
			}
		}
		return res;
	}
}
